
<%@ page contentType="text/html;charset=UTF-8" language="java" autoFlush="true" buffer="100kb" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@include file="/front-end/views/common/head.jsp"%>
    <title>上映管理</title>
    <Script type="text/javascript">
        $(function () {
            $("a.glyphicon-trash").click(function () {
                return confirm("你确定要删除【" + $(this).parent().parent().find("td:first").text() + "】?");
            });
        });
        function ajaxRequest(id) {
            var xmlhttprequest = new XMLHttpRequest();
            var url = "manage/releaseServlet?action=getSchedule&id="+id;
            xmlhttprequest.open("GET",url,true);
            xmlhttprequest.onreadystatechange = function(){
                if (xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200) {
                    // alert("收到服务器返回的数据：" + xmlhttprequest.responseText);
                    var data = JSON.parse(xmlhttprequest.responseText);
                    var play_id = document.getElementById('play_id');
                    play_id.value = data.play_id;
                    var studio_id = document.getElementById('studio_id');
                    studio_id.value = data.studio_id;
                    var sched_id = document.getElementById('sched_id');
                    sched_id.value = data.sched_id;
                    var play_ticket_price = document.getElementById('play_ticket_price');
                    play_ticket_price.value = data.play_ticket_price;
                    var sched_time = document.getElementById('sched_time');
                    sched_time.value = data.sched_time;
                }
            }
            xmlhttprequest.send();
        }
    </Script>

</head>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
      <%@include file="/front-end/views/common/manage_menu.jsp"%>
  </div>
</nav>
    <div id="main">
        <div class="itemone" >
                <!-- 按钮触发模态框 -->
                <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                </button>
                <!-- 模态框（Modal） -->
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                    &times;
                                </button>
                                <h4 class="modal-title" id="myModalLabel1">
                                    添加演出计划
                                </h4>
                            </div>
                            <div class="modal-body">
                                <form action="manage/releaseServlet?action=add&pageNo=${requestScope.page.pageTotal}" method="post">
                                    <div class="form-group">
                                        <label>影片名称：</label>
                                        <select name="play_id" >
                                            <c:forEach items="${requestScope.plays}" var="play" >
                                                <option value="${ play.play_id }">${ play.play_name }</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label>上映时间：</label>
                                        <input type="text" name="sched_time" class="form-control" placeholder="上映时间">
                                    </div>
                                    <div class="form-group">
                                        <label>演出厅：</label>
                                        <select name="studio_id" >
                                            <c:forEach items="${requestScope.studios}" var="studio" >
                                                <option value="${ studio.studio_id }">${ studio.studio_name }</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <input type="submit" value="提交" class="btn btn-primary">
                                </form>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                </button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>
            </div>
            <%--修改演出计划--%>
            <div>
                <div class="modal fade" id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                    &times;
                                </button>
                                <h4 class="modal-title" id="myModalLabel2">
                                    修改演出计划
                                </h4>
                            </div>
                            <div class="modal-body">
                                <form action="manage/releaseServlet?action=update&pageNo=${requestScope.page.pageNo}&id=${data.sched_id}" method="post">
                                    <div class="form-group">
                                        <input type="hidden" name="sched_id" id="sched_id">
                                        <label>影片名称：</label>
                                        <select name="play_id" id="play_id" >
                                            <c:forEach items="${requestScope.plays}" var="play" >
                                                <option value="${ play.play_id }">${ play.play_name }</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <label>上映时间：</label>
                                        <input type="date" id="sched_time" name="sched_time" class="form-control" placeholder="上映时间">
                                    </div>
                                    <div class="form-group">
                                        <label>演出厅：</label>
                                        <select name="studio_id" id="studio_id" >
                                            <c:forEach items="${requestScope.studios}" var="studio" >
                                                <option value="${ studio.studio_id }">${ studio.studio_name }</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <input type="submit" value="提交" class="btn btn-primary">

                                </form>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                </button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>

            </div>

            <%--正在热映--%>
            <table class="table table-hover">
                <%--                            正在热映--%>
                <thead>
                <tr style="height: 12px;">
                    <th>排片id</th>
                    <th>影片名称</th>
                    <th>上映时间</th>
                    <th>演出厅</th>
                    <th>票价</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${requestScope.page.items}" var="schedule" >
                    <tr>
                        <td>${schedule.sched_id}</td>
                        <td>${requestScope.plays[schedule.play_id-1].play_name}</td>
                        <td>${schedule.sched_time}</td>
                        <td>${requestScope.studios[schedule.studio_id-1].studio_name}</td>
                        <td>${schedule.sched_ticket_price}</td>
                        <td>
                            <a data-toggle="modal" onclick="ajaxRequest('${schedule.sched_id}')" data-target="#myModaledit"
                               class="glyphicon glyphicon-edit" aria-hidden="true"></a>
                            <a class="glyphicon glyphicon-option-vertical" aria-hidden="true"></a>
                            <a href="manage/releaseServlet?action=delete&sched_id=${schedule.sched_id}&pageNo=${requestScope.page.pageNo}" class="glyphicon glyphicon-trash" aria-hidden="true"></a>
                            <!--                                    </button>-->
                        </td>
                    </tr>
                </c:forEach>

                </tbody>
            </table>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
        $('#myModal').on('shown.bs.modal', function () {
          $('#myInput').focus()
        })
    </script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
</html>